import { Controller, Get, Post, Put, Delete, Body, Param, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { UserService } from './user.service';
import { CreateUserDto, UpdateUserDto, PaginationDto } from './dto';

@ApiTags('用户管理')
@Controller()
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get()
  @ApiOperation({ summary: '获取用户列表' })
  @ApiResponse({ status: 200, description: '获取用户列表成功' })
  findAll(@Query() paginationDto: PaginationDto) {
    return this.userService.findAll(paginationDto);
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取用户' })
  @ApiResponse({ status: 200, description: '获取用户成功' })
  findOne(@Param('id') id: string) {
    return this.userService.findOne(+id);
  }

  @Post()
  @ApiOperation({ summary: '创建用户' })
  @ApiResponse({ status: 201, description: '创建用户成功' })
  create(@Body() createUserDto: CreateUserDto) {
    return this.userService.create(createUserDto);
  }

  @Put(':id')
  @ApiOperation({ summary: '更新用户' })
  @ApiResponse({ status: 200, description: '更新用户成功' })
  update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
    return this.userService.update(+id, updateUserDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除用户' })
  @ApiResponse({ status: 200, description: '删除用户成功' })
  remove(@Param('id') id: string) {
    return this.userService.remove(+id);
  }

  @Get('by-username/:username')
  @ApiOperation({ summary: '根据用户名获取用户' })
  @ApiResponse({ status: 200, description: '获取用户成功' })
  findByUsername(@Param('username') username: string) {
    return this.userService.findByUsername(username);
  }

  @Get('by-openid/:openid')
  @ApiOperation({ summary: '根据微信openid获取用户' })
  @ApiResponse({ status: 200, description: '获取用户成功' })
  findByOpenid(@Param('openid') openid: string) {
    return this.userService.findByOpenid(openid);
  }
}

